<template>
  <div id="app">
    <router layer="layout" />
  </div>
</template>
<script>
import Router from './views/Router'

export default {
  components: {
    Router
  },
  mounted () {
    this.$store.commit('setView', {
      layer: 'layout',
      name: 'Discipline'
    })

    this.$http.beforeSend(this, async (action) => {
      try {
        // 显示提示框
        if (action.confirm) await this.$confirm(action.confirm)
        return true
      } catch (e) {
        return false
      }
    })

    this.$http.beforeSend(this, async (action, value) => {
      // console.log('action = ', action)
      // 跳转
      if (!action || !action.redirect) return true

      // console.log('value = ', value)
      const redirect = action.redirect
      const url = redirect.url || (redirect + '')
      const layer = redirect.layer || 'main'
      await this.$store.dispatch('reViewByUrl', {
        url, layer, value
      })
      return false
    })

    this.$http.onReceive(this, (response) => {
      if (response && response.message) {
        this.$message({
          message: response.message.text,
          type: response.message.type
        })
      }
    })

    this.$http.onException(this, (e) => {
      this.$message({
        message: e + '',
        type: 'error'
      })
    })
  }
}
</script>

<style lang="less">
body {
  height: 100%;
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
}

* {
  border: 0;
  padding: 0;
  margin: 0;
}

label {
  font-weight: 700;
}

html {
  height: 100%;
  box-sizing: border-box;
}

#app {
  height: 100%;
  color: #2c3e50;
  width: 100%;
}
</style>
